package com.ruoyi.project.jiaqin.area.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.area.domain.QuotationClassArea;
import com.ruoyi.project.jiaqin.area.service.IQuotationClassAreaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行情分类-产地（批发市场等）Controller
 *
 * @author LCL
 * @date 2021-11-02
 */
@Controller
@RequestMapping("/jiaqin/area")
public class QuotationClassAreaController extends BaseController
{
    private String prefix = "jiaqin/area";

    @Autowired
    private IQuotationClassAreaService quotationClassAreaService;

    @RequiresPermissions("jiaqin:area:view")
    @GetMapping()
    public String area()
    {
        return prefix + "/area";
    }

    /**
     * 查询行情分类-产地（批发市场等）列表
     */
    @RequiresPermissions("jiaqin:area:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuotationClassArea quotationClassArea)
    {
        startPage();
        List<QuotationClassArea> list = quotationClassAreaService.selectQuotationClassAreaList(quotationClassArea);
        return getDataTable(list);
    }

    /**
     * 导出行情分类-产地（批发市场等）列表
     */
    @RequiresPermissions("jiaqin:area:export")
    @Log(title = "行情分类-产地（批发市场等）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuotationClassArea quotationClassArea)
    {
        List<QuotationClassArea> list = quotationClassAreaService.selectQuotationClassAreaList(quotationClassArea);
        ExcelUtil<QuotationClassArea> util = new ExcelUtil<QuotationClassArea>(QuotationClassArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 新增行情分类-产地（批发市场等）
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行情分类-产地（批发市场等）
     */
    @RequiresPermissions("jiaqin:area:add")
    @Log(title = "行情分类-产地（批发市场等）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuotationClassArea quotationClassArea)
    {
        return toAjax(quotationClassAreaService.insertQuotationClassArea(quotationClassArea));
    }

    /**
     * 修改行情分类-产地（批发市场等）
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        QuotationClassArea quotationClassArea = quotationClassAreaService.selectQuotationClassAreaById(id);
        mmap.put("quotationClassArea", quotationClassArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存行情分类-产地（批发市场等）
     */
    @RequiresPermissions("jiaqin:area:edit")
    @Log(title = "行情分类-产地（批发市场等）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuotationClassArea quotationClassArea)
    {
        return toAjax(quotationClassAreaService.updateQuotationClassArea(quotationClassArea));
    }

    /**
     * 删除行情分类-产地（批发市场等）
     */
    @RequiresPermissions("jiaqin:area:remove")
    @Log(title = "行情分类-产地（批发市场等）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(quotationClassAreaService.deleteQuotationClassAreaByIds(ids));
    }
}
